package modules.pooling;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池
 *     工具类 Executors 三大方法；
 * @author shengren.yan
 * @create 2021-03-12
 */
public class Executors1 {

    // 创建线程池
    public static void main(String[] args) {

//     ExecutorService executorService = Executors.newSingleThreadExecutor();  //单个线程
//     ExecutorService executorService = Executors.newFixedThreadPool(5);    //创建一个固定的线程池的大小
       ExecutorService executorService = Executors.newCachedThreadPool();    //可伸缩的

        try {
            for (int i=1; i<=80; i++){
                //使用线程池之后创建线程
                executorService.execute(()->{
                    System.out.println(Thread.currentThread().getName()+ " ok");
                });
            }
        } finally {
            executorService.shutdown();
        }

    }

}
